package com.tsl.prevention.modules.wechat.serviceImpl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tsl.prevention.modules.wechat.WeixinService;
import com.tsl.prevention.util.Result;
import com.tsl.prevention.util.UrlUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA 2017.1 <br>
 * User: zhangrui [loverochy8@gmail.com] <br>
 * Date: 2020/6/21 13:17 <br>
 * To change this template use File | Settings | File Templates. <br>
 * Description:
 */
@Service
public class WeixinServiceImpl {
    String appId = "wx21f45e54c1bd8a8e";
    String appSecret = "9993ae87da25e0951aa42a1769e2262e";
    public JSONObject getUserWXLoginInfo(String wxCode) {
        String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
        Map<String,String> requestUrlParam = new HashMap<String,String>();
        requestUrlParam.put("appid", appId);	//开发者设置中的appId
        requestUrlParam.put("secret", appSecret);	//开发者设置中的appSecret
        requestUrlParam.put("js_code", wxCode);	//小程序调用wx.login返回的code
        requestUrlParam.put("grant_type", "authorization_code");	//默认参数
        //发送post请求读取调用微信 https://api.weixin.qq.com/sns/jscode2session 接口获取openid用户唯一标识
        JSONObject jsonObject = JSON.parseObject(UrlUtil.sendPost(requestUrl, requestUrlParam));
        return jsonObject;
    }
}
